package org.bigjava.user.util;

import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.Date;

public class DateUtil {
    java.util.Date date = new Date();//获得当前时间
    Timestamp t = new Timestamp(date.getTime());
    LocalDate now = LocalDate.now();

    /**
     * 计算传入时间和现在相差多少日
     *  用于计算用户注册时长
     * @param date
     * @return
     */
    @Deprecated
    public long getUserday(Timestamp date){

        long t1 = t.getTime();
        long t2 = date.getTime();
        long day = (t1-t2)/(1000*60*60*24);
        return day;
    }



    /**
     * 计算传入时间和现在相差多少日
     * 用于计算用户注册时长
     * @param date1
     * @return
     */
    public long getUserDay(Timestamp date1){

        LocalDate date = date1.toLocalDateTime().toLocalDate();
        long between = ChronoUnit.DAYS.between( date, now);

        return between;
    }

    /**
     * 判断时间是否超过当前时间
     * @param date1
     * @return
     */
    public boolean After(Timestamp date1){

        LocalDate date = date1.toLocalDateTime().toLocalDate();

        return date.isAfter(now);
    }

    /**
     * 判断当前时间是否和传入时间相同，可用于判断用户生日
     * @param date1
     * @return
     */
    public boolean Equal(Timestamp date1){

        LocalDate date = date1.toLocalDateTime().toLocalDate();

        return date.isEqual(now);
    }

}